/* build.groovy
    ##################################################
    # Created by zy                        #
    # Plugin install:  build user vars, maven node build                                                #
    # A Part of the Project jenkins-library          #
    ##################################################
*/

package org.devops

def generateDockerfile(dockersvc_type, dockerfilename){
        switch(dockersvc_type){
            case 'jar':
                def data = libraryResource dockerfilename
                // data = data.replace("SERVICE_NAME", "${env.JOB_BASE_NAME}")
                writeFile(file: 'Dockerfile', text: data)
                println(data)
        }
}


def dockerbuild(dhub_cred,image_name,registry){
    withCredentials([usernamePassword(credentialsId: dhub_cred, passwordVariable: 'password', usernameVariable: 'username')]) {
        sh "docker build -t $image_name  ."
        sh "docker login -u ${username} -p '${password}'  $registry" 
        sh "docker push $image_name" 
        // sh "cat Dockerfile"
    }
}